#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include "output.h"
#include "pch.h"

using namespace std;

void outputRes(const char *path, int res, char *result[], int len, bool toFile) {
    if(toFile) {
//        cout << path << endl;
        string outPath = path, solPath;
        for (int i = (int )outPath.size() - 1;i >= 0;i--) {
            if (outPath[i] == '/' || outPath[i] == '\\') {
                for (int j = 0;j <= i;j++) {
                        solPath += outPath[j];
                }
                break;
            }
        }
        solPath += "solution.txt";
//        cout << solPath << endl;
        FILE *fp = nullptr;
        int r = freopen_s(&fp, solPath.c_str(), "w", stdout);
        for (int i = 0;i < len;i++) {
            cout << result[i] << endl;
        }
        r = freopen_s(&fp, "CON", "w", stdout);
    } 
    else {
        cout << res << endl;
        for (int i = 0;i < len;i++) {
            cout << result[i] << endl;
        }
//        cout << result[len - 1];
    }
}